<?php
namespace common\models;


class BalanceOperate extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'balance_operate';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['member_id', 'balance_type', 'create_time', 'update_time'], 'integer'],
            [['nums'], 'number'],
            [['member_name', 'operator'], 'string', 'max' => 32],
            [['type'], 'string', 'max' => 1],
            [['remark'], 'string', 'max' => 64],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'member_id' => '会员ID',
            'member_name' => '姓名',
            'nums' => '金额',
            'balance_type' => '账本类型',
            'type' => '类型 1增加 2减少',
            'remark' => '备注',
            'operator' => '操作人',
            'create_time' => '创建时间',
            'update_time' => 'Update Time',
        ];
    }    

	/*
		* 数据列表
		* whereArr 条件
		* params 基本参数 包含 field order page limit
		* extends  扩展信息 一些相关的信息
		* 
	*/	
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
		$models = self::queryFormart($model,$where,$params,$whereAnd);
		$model  = $models['model'];
		
		$data  = $model->asarray()->all();
		if(!$data) return array();

		//扩展信息
		if(!$extends) return $data;

		foreach($extends as $extend)
		{

		}

		return $data;	
	}

	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->one();
	}


	public static function getAll($where = [], $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->all();
	}

}